While you want to give lots of suggestions, you don't want to give bad suggestions, so you decide to use a list comprehension since you can easily generate outfit combinations, then filter them by some criteria.
Clothing items are stored as a map:
%{
item_name: "Descriptive Name",
price: 99.00,
base_color: "red"
}
Implement get_combinations/3 to take a list of tops, a list of bottoms, and keyword list of options. For now, set options to default to an empty keyword list. The function should return the cartesian product of the lists.
Each piece of clothing has a :base_color field, use this field to filter out all combinations where the top and the bottom have the same base color.
Each piece of clothing has a :price field associated with it. While you want to give lots of suggestions, you want to be able to provide users an opportunity to select a price within their budget. From the keyword list of options, use :maximum_price to filter out combinations where the price of the top and bottom exceed the maximum price.
If no maximum_price is specified, the default should be 100.00
https://exercism.org/tracks/elixir/exercises/boutique-suggestions
defmodule BoutiqueSuggestions do
@moduledoc """
practice list comprehensions
"""
def get_combinations(tops, bottoms, options \\ []) do
value = Keyword.get(options, :maximum_price, 100)
for top_item <- tops,
bottom_item <- bottoms,
bottom_item.base_color !== top_item.base_color and
top_item.price + bottom_item.price <= value,
do: {top_item, bottom_item}
end
end